package com.totoro.utils;

import java.util.HashMap;
import java.util.Map;

public class ReturnFormat {
    private static Map<String,String> messageMap =new HashMap();
    //初始化状态码与文字说明
    static {
        messageMap.put("400", "Bad Request!");
        messageMap.put("401", "NotAuthorization");
        messageMap.put("404", "Resource is not available");
        messageMap.put("405", "Method Not Allowed");
        messageMap.put("406", "Not Acceptable");
        messageMap.put("500", "Internal Server Error");
    }
    //出现异常时调用
    public static String retParam(int code) {
        OutputJson json = new OutputJson(code, messageMap.get(String.valueOf(code)));
        return json.toString();
    }

    public static String retData(Object data, boolean isSuccess){
        OutputJson json = new OutputJson(200, "normal");
        json.setData(data);
        json.setSuccess(isSuccess);
        return json.toString();
    }
}
